package alg20250213;

public class Text {
    public int minSubArrayLen(int target, int[] nums) {
        int n = nums.length;
        int sum = 0, left = 0, right = 0;
        int len = Integer.MAX_VALUE;
        while(right < n){
            //进窗口
            sum += nums[right];
            //判断
            while(sum >= target) {
                //更新结果
                len = Math.min(len, right - left + 1);
                //出窗口
                sum -= nums[left++];
            }
            right++;
        }
        return len == Integer.MAX_VALUE ? 0 : len;
    }
}
